<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <script src="js/jquery-3.3.1.js"></script>
    <title>发布文章</title>
    <style>
        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
            padding: 0;
            font-family: Arial, sans-serif;
            background-color: #e4b9c0;
        }

        .header {
            /*background-color: #f0f0f0;*/
            background-color: #afd9ee;
            padding: 20px;
            text-align: center; /* 将标题居中对齐 */
        }

        .content {
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }

        form {
            display: grid;
            grid-gap: 10px;
            flex-direction: column;
        }

        label {
            font-weight: bold;
        }

        input[type="text"],
        select,
        textarea {
            width: 100%;
            padding: 5px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        .visible {
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: flex-start;
            gap: 10px;
            background-color: #e4b9c0;
        }

        button[type="submit"] {
            padding: 10px 20px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        button[type="submit"]:hover {
            background-color: #0056b3;
        }
    </style>


    <script>

        //查询分类数据
        $(function () {
            $.get("category/findAll", {}, function (data) {

                var lis = '<option value="">请选择分类</option>';
                // //遍历请求回来的json数组，拼接字符串
                for (let i = 0; i < data.length; i++) {
                    var li = '<option value="' + data[i].cid + '">' + data[i].cname + '</option>';
                    lis += li;
                }
                //将lis字符串设置到ul的html内容中
                $("#category").html(lis);
            });
        });

        //展示标签
        $(function () {
            $.get("label/findAll", {}, function (data) {
                // //遍历请求回来的json数组，拼接字符串
                var lis = "";
                for (let i = 0; i < data.length; i++) {
                    var li = '<option id="tag" value="' + data[i].lid + '">' + data[i].lname + '</option>';
                    lis += li;
                }
                //将lis字符串设置到ul的html内容中
                $("#tags").html(lis);
            });
        });

        //提交文章内容
        $(function () {
            $("#publishButton").click(function () {
                $.post("user/publishArticle", $("#form").serialize(), function (data) {
                    //
                    // if (data.success) {
                    //     alert(data.message); // 弹出发布成功的提示信息
                    // } else {
                    //     alert(data.error); // 弹出发布失败的提示信息
                    // }
                });
                alert("发布成功!")
            });
        });
    </script>
<body>
<header class="header">
    <h1>发布文章</h1>
</header>
<div class="content">
    <form id="form">
        <label for="title">标题:</label>
        <input type="text" id="title" name="title" required>

        <label for="category">分类:</label>
        <select id="category" name="category" required>
            <!--            <option value="">请选择分类</option>-->
        </select>


        <label for="tags">标签:</label>
        <select id="tags" name="tags" multiple required>
            <!--            <option value="标签1">标签1</option>-->

        </select>
        <div>
            <tr class="visible">
                <td class="td_left">
                    <label for="visible">浏览权限:</label>
                </td>
                <td class="td_right">
                    <input type="radio" id="visible" name="visible" value="Y" checked> 公开
                    &nbsp;
                    &nbsp;
                    &nbsp;
                    <input type="radio" name="visible" value="N"> 仅自己可见
                </td>
            </tr>
        </div>

        <label for="content">文章内容:</label>
        <textarea id="content" name="content" rows="8" required></textarea>

        <button type="submit" id="publishButton" class="button">发布</button>
        <button type="button" onclick="window.location.href='person.html'">返回</button>
    </form>
</div>

</body>
</html>